<import file="block/common.html" name="url" :tpl_cfg="['urlName'=>'栏目列表']"/>
<div class="layui-fluid">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md12">

			<div class="layui-btn-container">
                <div class="layui-btn-group">
                    <?php echo SysRolCk("contentcate_add")?'<button class="layui-btn layui-btn-sm data-add-btn"><i class="layui-icon">&#xe61f;</i> '.lang('add').' </button>':''; ?>
                    <button id="btnExpandAll" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe622;</i> 全部展开 </button>
                    <button id="btnFoldAll" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe758;</i> 全部折叠 </button>
                </div>
            </div>
<table class="layui-hide" id="currentTableId"></table>
			<script type="text/html" id="catetypeTableBar">
				{{#  if(d.type == 1){ }}
					列表
				{{#  }else{ }}
					<b style="color:red">频道</b>
				{{#  } }}
			</script>
			<script type="text/html" id="ctcount">
				{{#  if(d.type == 1){ }}
					{{#  if(d.ct == 1){ }}
					<i class="layui-icon layui-icon-ok"></i> 
					{{#  } }}
				{{#  } }}
			</script>

			<script type="text/html" id="nameTmp">
				<a href="/list/{{d.id}}" target="_blank">{{d.name}}</a>	
		   </script>

		   <script type="text/html" id="icoTableBar">
					<i class="layui-icon {{d.ico}}"></i> 
			</script>

			<script type="text/html" id="themeColor">
				{{#  if(d.type == 1){ }}
					{{#  if(d.color.length < 1){ }}
						<span class="layui-badge-rim"><i class="layui-icon">&#xe66a;</i></span>
					{{#  }else{ }}
						<span class="layui-badge-rim"><i class="layui-icon" style="color:{{ d.color }};">&#xe66a;</i></span>
					{{#  } }}
				{{#  } }}
			</script>

			<script type="text/html" id="currentTableBar">
				<div class="layui-btn-group">
					<?php if(SysRolCk("contentcate_edit")){ ?>
					<a class="layui-btn layui-btn-sm data-count-edit" lay-event="edit"><i class="layui-icon">&#xe642;</i><?php echo lang('edit');?> </a>
					<?php } ?>
					<?php  if(SysRolCk("contentcate_del")) { ?>
						<a class="layui-btn layui-btn-sm layui-btn-danger data-count-delete" lay-event="delete"><i class="layui-icon">&#xe640;</i>删除</a>
					<?php }else{ ?>
						<a class="layui-btn layui-btn-xs layui-btn-disabled">删除</a>
					<?php } ?>
				</div>	
			</script>
		</div>
	</div>
</div>
<script>
	layui.define(['treeTable'],function () {
		var $ = layui.jquery,
		treeTable = layui.treeTable,
        form = layui.form;

		treeTable.render({
			elem: '#currentTableId',
			text: {
				none: '<div style="padding: 18px 0;">无数据</div>'
			},
			url: '<{CAUrl("contentcate","index")}>&list_json',
			cols: [[
				//{type: 'numbers'},
				//{field: 'pid', title: 'PID'},
				{ field: 'id', title: 'ID', width: 50 },
				{ field: 'name', title: '栏目名称', width: 200 , templet: '#nameTmp' },
				{ field: 'type', title: '类型',width: 60, templet: '#catetypeTableBar' },
				{ field: 'sort', title: '排序',width: 60, edit: 'text'},
				{ field: 'theme', title: '模板', width: 200},
				{ field: 'contheme', title: '内容模板', width: 200},
				{ field: 'num', title: '前台条数',width: 100, align: "center"},
				{ field: 'ico', title: '图标',width: 80, minWidth: 50, templet: '#icoTableBar', fixed: "right", align: "center" },
				{ field: 'color', title: '颜色标识',width: 100, templet: '#themeColor', align: "center"},
				{ field: 'ct', title: '统计',width: 40, templet: '#ctcount'},
				{ field: 'urlname', title: 'URL'},
				{ title: '操作', minWidth: 140,width: 220, templet: '#currentTableBar', fixed: "right", align: "center" }
			]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 5,
            id: 'currentTableId',
		});

		$(".data-add-btn").on("click", function () {
			loadMain('<{CAUrl("contentcate","add")}>&view');
			return false;
		});

		// 全部展开
		$('#btnExpandAll').click(function () {
			treeTable.expandAll("currentTableId", true)
		});

		// 全部折叠
		$('#btnFoldAll').click(function () {
			treeTable.expandAll("currentTableId", false)
		});

		//监听单元格编辑
        treeTable.on('edit(currentTableId)', function (obj) {
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
			$.post('<{CAUrl("contentcate","edit")}>&sortedit&id=' + data.id, {sort:value}, function (res) {
                if (res.status == 1) {
					layer.msg(res.info, { icon: 1, time: 1000 }, function () {
						treeTable.reloadData('currentTableId');
					});
				} else {
					layer.msg(res.info, { icon: 2, anim: 6, time: 5000 });
				}
            });
        });


		treeTable.on('tool(currentTableId)', function (obj) {
			var data = obj.data;
			if (obj.event === 'edit') {
				loadMain('<{CAUrl("contentcate","edit")}>&view&id=' + data.id);
				return false;
			} else if (obj.event === 'delete') {
				layer.confirm('删除确认？', function (index) {
					$.post('<{CAUrl("contentcate","del")}>', data, function (res) {
						if (res.status == 1) {
							layer.msg(res.info, { icon: 1, time: 1000 }, function () {
								obj.del();
								layer.close(index);
							});
						} else {
							layer.msg(res.info, { icon: 2, anim: 6, time: 5000 });
						}
					});
				});
			}
		});

		
	});

</script>